package main

import (
	"bytes"
	"fmt"
	"github.com/gin-gonic/gin"
	"os/exec"
)

func main() {
	r := gin.New()
	r.GET("/updatewechat", func(c *gin.Context) {
		shPath := "/Users/kidswant/Bot/update.sh"
		openCmd := "bash"
		cmd := exec.Command(openCmd, shPath)
		var out bytes.Buffer
		var stderr bytes.Buffer
		cmd.Stdout = &out
		cmd.Stderr = &stderr
		err := cmd.Run()
		if err != nil {
			c.JSON(200, gin.H{
				"message": fmt.Sprint(err) + ": " + stderr.String(),
			})
			return
		}
		c.JSON(200, gin.H{
			"message": "update wechat success",
		})

	})

	r.GET("/status", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"code": 1001,
			"msg":  "server is ok",
		})
	})

	r.Run(":3001")
}
